#!/bin/bash -e
# Copyright (C) 2022 Simo Sorce <simo@redhat.com>
# SPDX-License-Identifier: Apache-2.0

source "${TESTSSRCDIR}/helpers.sh"

SECRETFILE=${TMPPDIR}/rsa-oaep-secret.txt
echo "Super Secret" > "${SECRETFILE}"
title PARA "Encrypt and decrypt with RSA OAEP"
# Let openssl encrypt by importing the public key
ossl '
pkeyutl -encrypt -inkey "${BASEURI}"
                 -pubin
                 -pkeyopt pad-mode:oaep
                 -pkeyopt digest:sha256
                 -pkeyopt mgf1-digest:sha256
                 -in ${SECRETFILE}
                 -out ${SECRETFILE}.enc'
ossl '
pkeyutl -decrypt -inkey "${PRIURI}"
                 -pkeyopt pad-mode:oaep
                 -pkeyopt digest:sha256
                 -pkeyopt mgf1-digest:sha256
                 -in ${SECRETFILE}.enc
                 -out ${SECRETFILE}.dec'
diff "${SECRETFILE}" "${SECRETFILE}.dec"
